function projectList(name){
	$.ajax({
		url : 'http://projects/list',
		dataType : 'json',
		success : function(data){
			var projectList = data.list || [];
			var html = '';
			for(var i=0; i<projectList.length; i++){
				html = html + '<div class=\"project-item\" id="'+projectList[i].projectid+'">';
				html = html + '<h3>'+projectList[i].projectName+'</h3>';
				html = html + '<div class=\"project-item-box\">';
				html = html + '<div class=\"item-status\">';
				html = html + '<p class=\"item-status-pending '+projectList[i].pstatus+'\"></p>';
				html = html + '<p class=\"item-status-approved '+projectList[i].pstatus+'\"></p>';
				html = html + '<p class=\"item-status-completed '+projectList[i].pstatus+'\"></p>';
				html = html + '</div>';
				html = html + '<div class=\"project-item-msg\">';
				html = html + '<ul class=\"project-item-msgDisply\">';
				html = html + '<li><div class=\"client-name\">client:<a>'+projectList[i].clientName[i]+'</a></div></li>';
				html = html + '<li><div>StartDate:<span>'+projectList[i].projectStartDate+'</span></div></li>';
				html = html + '<li><div class=\"project-mgr\">project mgr:<a>'+projectList[i].projectManagerName[i]+'</a>';
				html = html + '<a class=\"project-mgr-email\" href=\"mailto:'+projectList[i].projectManagerEmail+'\"></a></div>';
				html = html + '</li>';
				html = html + '</ul>';
				html = html + '</div>';
				html = html + '</div>';
				html = html + '<div class=\"project-item-tools\">';
				html = html + '<a class=\"meetM-btn\">meeting minutes</a>';
				html = html + '</div>';
				html = html + '</div>';
			}
			$(".project-list").append(html);
			projectClick();
		}
	})	
}
projectList();

function selectChoose(){
	$.ajax({
		url : 'http://projects/list',
		dataType : 'json',
		success : function(data){
			var projectList = data.list || [];
			var html = '';
			html = html + '<select id="clientChoose" onChange="clientChoose(this.value)">';
			html = html + '<option value="Client">Client</option>';
			for(var i=0; i<projectList.length; i++){
				html = html + '<option client="'+projectList[i].clientId+'" value="'+projectList[i].clientName[i]+'">'+projectList[i].clientName[i]+'</option>';
			}
			html = html + '</select>';
			html = html + '<select id="managerChoose" onChange="managerChoose(this.value)">';
			html = html + '<option value="Project Manage">Project Manage</option>';
			for(var i=0; i<projectList.length; i++){
				html = html + '<option Manager="'+projectList[i].projectManagerId+'" value="'+projectList[i].projectManagerName[i]+'">'+projectList[i].projectManagerName[i]+'</option>';
			}
			html = html + '</select>';
			$(".select-choose").append(html);
		}
	})	
}
selectChoose();
function managerChoose(name){
	//alert(name);
	$(".project-list").empty();
	$.ajax({
		url : 'http://projects/list',
		dataType : 'json',
		success : function(data){
			var projectList = data.list || [];
			var html = '';
			for(var i=0; i<projectList.length; i++){
				if(projectList[i].projectManagerName[i]==name){
				html = html + '<div class=\"project-item\" id="'+projectList[i].projectid+'">';
				html = html + '<h3>'+projectList[i].projectName+'</h3>';
				html = html + '<div class=\"project-item-box\">';
				html = html + '<div class=\"item-status\">';
				html = html + '<p class=\"item-status-pending '+projectList[i].pstatus+'\"></p>';
				html = html + '<p class=\"item-status-approved '+projectList[i].pstatus+'\"></p>';
				html = html + '<p class=\"item-status-completed '+projectList[i].pstatus+'\"></p>';
				html = html + '</div>';
				html = html + '<div class=\"project-item-msg\">';
				html = html + '<ul class=\"project-item-msgDisply\">';
				html = html + '<li><div class=\"client-name\">client:<a>'+projectList[i].clientName[i]+'</a></div></li>';
				html = html + '<li><div>StartDate:<span>'+projectList[i].projectStartDate+'</span></div></li>';
				html = html + '<li><div class=\"project-mgr\">project mgr:<a>'+projectList[i].projectManagerName[i]+'</a>';
				html = html + '<a class=\"project-mgr-email\" href=\"mailto:'+projectList[i].projectManagerEmail+'\"></a></div>';
				html = html + '</li>';
				html = html + '</ul>';
				html = html + '</div>';
				html = html + '</div>';
				html = html + '<div class=\"project-item-tools\">';
				html = html + '<a class=\"meetM-btn\">meeting minutes</a>';
				html = html + '</div>';
				html = html + '</div>';
				}
			}
			$(".project-list").append(html);
			projectClick();
		}
	})
}

function clientChoose(name){
	//alert(name);
	$(".project-list").empty();
	$.ajax({
		url : 'http://projects/list',
		dataType : 'json',
		success : function(data){
			var projectList = data.list || [];
			var html = '';
			for(var i=0; i<projectList.length; i++){
				if(projectList[i].clientName[i]==name){
				html = html + '<div class=\"project-item\" id="'+projectList[i].projectid+'">';
				html = html + '<h3>'+projectList[i].projectName+'</h3>';
				html = html + '<div class=\"project-item-box\">';
				html = html + '<div class=\"item-status\">';
				html = html + '<p class=\"item-status-pending '+projectList[i].pstatus+'\"></p>';
				html = html + '<p class=\"item-status-approved '+projectList[i].pstatus+'\"></p>';
				html = html + '<p class=\"item-status-completed '+projectList[i].pstatus+'\"></p>';
				html = html + '</div>';
				html = html + '<div class=\"project-item-msg\">';
				html = html + '<ul class=\"project-item-msgDisply\">';
				html = html + '<li><div class=\"client-name\">client:<a>'+projectList[i].clientName[i]+'</a></div></li>';
				html = html + '<li><div>StartDate:<span>'+projectList[i].projectStartDate+'</span></div></li>';
				html = html + '<li><div class=\"project-mgr\">project mgr:<a>'+projectList[i].projectManagerName[i]+'</a>';
				html = html + '<a class=\"project-mgr-email\" href=\"mailto:'+projectList[i].projectManagerEmail+'\"></a></div>';
				html = html + '</li>';
				html = html + '</ul>';
				html = html + '</div>';
				html = html + '</div>';
				html = html + '<div class=\"project-item-tools\">';
				html = html + '<a class=\"meetM-btn\">meeting minutes</a>';
				html = html + '</div>';
				html = html + '</div>';
				}
			}
			$(".project-list").append(html);
			projectClick();
		}
	})	
}
function creatProject(){
	$.ajax({
		url: 'http://pmo/list',
		dataType: 'json',
		success: function(data){
			var html = '';
			var date = new Date();
			var proId = data.list || [];
			var company = data.list[1].company[1],
				year = date.getFullYear(),
				order = data.list[1].pmoid;
			var CL=company.toString().length;
			//alert(CL);
			html = html + '<li>';
			html = html + '<label>Project I0D</label>';
			html = html + '<p><input id="newProject_ProjectId" class="form-control" type="text" name="projectID" readonly="true" value="'+company+year+order+'"/></P>';
			html = html + '</li>';
			$(".newProject-msg ul form").prepend(html);
		}
		
	})
	
}

function meetingMin(proName){
	$(".meetingM-tab-section").empty();
	$.ajax({
		url: 'http://minutes/list',
		dataType: 'json',
		success: function(data){
			var html = '';
			var minutesList = data.list || [];
			html = html + '<h3>'+proName+'</h3>';
			for(i=0; i<minutesList.length; i++){
				html = html + '<div class="meetingM-item" id="'+minutesList[i].minutesId+'">';
				html = html + '<ul>';
				html = html + '<li>created:<span>'+minutesList[i].createDate+'</span></li>';
				html = html + '<li>created by:<span>'+minutesList[i].createdBy+'</span></li>';
				html = html + '<li>approved:<span>'+minutesList[i].approved+'</span></li>';
				html = html + '<li><a>open</a></li>';
				html = html + '</ul>';
				if(minutesList[i].comment == 'yes'){
					html = html + '<div class="meetingM-item-comment">';
					html = html + '<p>Comment:</p>';
					html = html + '<p>';
					html = html + '<span class="comment_ele">2017/12/13</span>';
					html = html + '<span class="comment_ele">Micah Cheng</span>';
					html = html + '<span>"Please also update the feedback from client into the report."</span>';
					html = html + '<a>more</a>';
					html = html + '<p>';
					html = html + '</div>';
				}else{
					html = html + '<p>no</p>';
				}
				html = html + '</div>';
			}
			$(".meetingM-tab-section").append(html);
		}
	})
	
}